Optimize stringifyCookie by 2x for cookie-octet values#269
Optimize stringifyCookie by 2x for cookie-octet values#269saripovdenis wants to merge 7 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #269 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 1 1
Lines 160 260 +100
Branches 69 118 +49
==========================================
+ Hits 160 260 +100 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@blakeembrey what do you think about this tradeoff? |
|
This looks pretty great! I think it's worth the trade-off. One question, should we just allow all RFC valid values through without encoding? It may differ slightly from |
Great idea! Some cases would have different behaviour stringifyCookie({ foo: "a=b" })
// before: foo=a%3Db
// after: foo=a=bBut overall looks like a great win from perf side! I pushed code accordingly |
|
Hi @blakeembrey Friendly ping~ |
|
There's an existing regex |
|
Also I'm planning to land this in a new major version to eliminate concerns around breaking changes. If you want this in the current version I can cherry pick your original commit, just let me know. |
In vacuum I would make so I would keep cookieValueRegExp the same as now to be more permissive for people who need it |
stringifyCookieOptimizationOptimizes default cookie encoding by skipping
encodeURIComponentwhen values are already roundtrip-safe cookie-octets.%is still encoded to preserve roundtrip behavior:Benchmarks
emptysimplerfc cookie-octetsencodeundefined valuesmixed encode10 cookies100 cookiesSummary
rfc cookie-octets: 2.05x fastersimple: 1.51x faster10 cookies: 1.46x faster100 cookies: 1.37x fasterencodecase: 0.91x, slower because it checks the fast-path regexp before falling back toencodeURIComponent